﻿@model PluginsViewModel
@{
	ViewBag.Title = "Manage plugins";
}

@section help
{
	TODO
}

<h2>Installed plugins</h2>

<ul class="listview">
	@foreach (var plugin in Model.InstalledPlugins)
	{
		<li>
			<span class="item-title">@plugin.Name</span>
			<div class="item-sub">@plugin.Description</div>
			<div class="item-cmds">
				@using (Html.BeginForm("Uninstall", "Plugins", new { name = plugin.Name }, FormMethod.Post, new { @class = "inline" })) {
					@Html.AntiForgeryToken()
					<a href="#" class="cmd uninstalllink">Uninstall</a>
				}
				&nbsp;
			</div>
		</li>
	}
</ul>

<h2>Available plugins</h2>

<ul class="listview">
	@foreach (var plugin in Model.AvailablePlugins)
	{
		<li>
			<span class="item-title">@plugin.Name</span>
			<div class="item-sub">@plugin.Description</div>
			<div class="item-cmds">
				@using (Html.BeginForm("Install", "Plugins", new { name = plugin.Name }, FormMethod.Post, new { @class = "inline" })) {
					@Html.AntiForgeryToken()
					<a href="#" class="cmd installlink">Install</a>
				}
				&nbsp;
			</div>
		</li>
	}
</ul>

<script type="text/javascript">
	$(document).ready(function () {
		$('a.installlink').click(function () {
			$(this).closest('form').submit();
			return false;
		});

		$('a.uninstalllink').click(function () {
			if (confirm('Are you sure you want to uninstall this plugin?')) {
				$(this).closest('form').submit();
			}
			return false;
		});
	})
</script>
